//
//  FiltrateSectionTitleView.m
//  TerritoryShopkeeper
//
//  Created by xiaowu on 2017/12/18.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "FiltrateSectionTitleView.h"

@implementation FiltrateSectionTitleView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self configure];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self configure];
}

- (void)configure {
    self.view = [[[NSBundle mainBundle] loadNibNamed:@"FiltrateSectionTitleView" owner:self options:nil] firstObject];
    self.view.frame = self.bounds;
    [self addSubview:self.view];
    
    self.titleLabel.font = TextPingFangFontSize(12);
    self.titleLabel.textColor = [UIColor blackTextColor];
    
    self.subTitleLabel.font = TextPingFangFontSize(12);
    self.subTitleLabel.textColor = [UIColor grayTextColor];
    
    
    self.state = FiltrateSectionStateForRetract;
    
    
    
}

- (void)setValueWithTitle:(NSString *)title {
    self.titleLabel.text = title;
}

#pragma mark - Setters
- (void)setState:(FiltrateSectionState)state {
    _state = state;
    if (state == FiltrateSectionStateForRetract) {
        self.imageView.image = [UIImage imageNamed:@"open_arrow"];
        self.subTitleLabel.text = @"展开";
    } else if (state == FiltrateSectionStateForOpen) {
        self.imageView.image = [UIImage imageNamed:@"retract_arrow"];
        self.subTitleLabel.text = @"收起";
    } else if (state == FiltrateSectionStateForNone) {
        self.imageView.hidden = YES;
        self.subTitleLabel.hidden = YES;
    }
}

#pragma mark - Action
- (IBAction)buttonClick:(id)sender {
    
    if (self.state == FiltrateSectionStateForRetract) {
        [self setState:FiltrateSectionStateForOpen];
    } else if (self.state == FiltrateSectionStateForOpen) {
        [self setState:FiltrateSectionStateForRetract];
    } else if (self.state == FiltrateSectionStateForNone) {
        return;
    }
    if (self.block) {
        self.block();
    }

}


@end
